package com.wxj.book.cms.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wxj.book.cms.dao.CommentMapper;
import com.wxj.book.cms.pojo.Comment;
import com.wxj.book.cms.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    private CommentMapper commentMapper;

    /***
     * 查询全部
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<Comment> getAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Comment> comments = commentMapper.getAll();
        PageInfo<Comment> pageInfo = new PageInfo<>(comments);
        return pageInfo;
    }

    /**
     * 更新评论状态
     * @param comment
     * @return
     */
    @Override
    public int update(Comment comment) {
        Comment newComment = new Comment();
        newComment.setId(comment.getId());
        newComment.setStatus(comment.getStatus());
        return commentMapper.updateByPrimaryKeySelective(newComment);
    }

    /**
     * 根据id删除
     * @param commentId
     * @return
     */
    @Override
    public int deleteById(Integer commentId) {
        return commentMapper.deleteByPrimaryKey(commentId);
    }
}
